//
//  HMStatusRetweetView.swift
//  微博
//
//  Created by 程双岐 on 16/9/23.
//  Copyright © 2016年 heima. All rights reserved.
//

import UIKit

class HMStatusRetweetView: UIView {
    
    var retweetViewBottomConstraint: Constraint?
    
    var statusViewModel: HMStadusViewModel?{
        didSet{
            
            contentLabel.text = statusViewModel?.retweetContent
            contentLabel.attributedText = statusViewModel?.retweetAttruvutedString
            
            retweetViewBottomConstraint?.uninstall()
//            pictureView.picUrls = statusViewModel?.status?.retweeted_status?.pic_urls
            if let picture = statusViewModel?.status?.retweeted_status?.pic_urls, picture.count > 0{
                pictureView.isHidden = false
                self.snp_updateConstraints(closure: { (make) in
                   retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(HMHHomeTableViewCellMargin).constraint
                })
                pictureView.picUrls = picture
            }else{
                
                pictureView.isHidden = true
                self.snp_updateConstraints(closure: { (make) in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(HMHHomeTableViewCellMargin).constraint
                })
            }
            
        }
    }
    

    private lazy var contentLabel: UILabel = {
       let label = UILabel(textColor: UIColor.lightGray, fontSize: 13)
        label.numberOfLines = 0
        label.text = "哈哈哈哈"
        return label
    }()
    
    private lazy var pictureView: HMStatusPictureView = {
        let view = HMStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI(){
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
        contentLabel.snp_makeConstraints { (make) in
            make.top.equalTo(self).offset(HMHHomeTableViewCellMargin)
            make.leading.equalTo(self).offset(HMHHomeTableViewCellMargin)
            make.width.equalTo(ScrenWidth - 2 * HMHHomeTableViewCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) in
            make.leading.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(HMHHomeTableViewCellMargin)
        }
        
        self.snp_makeConstraints { (make) in
           retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(HMHHomeTableViewCellMargin).constraint
        }

    }

}
